
package com.lesama.collection;

/*
    Collection的常用方法：
        public boolean add(E e): 把给定的对象添加到当前集合中
        public void clear(): 清空集合中的元素
        public boolean isEmpty(): 判断当前集合是否为空
        public boolean remove(E e): 把给定的对象从当前集合中删除
        public boolean contains(Object obj): 判断当前集合中是和包含给定的对象
        public int size(): 返回集合中元素的个数（集合的长度）
    remove(), contains()底层依赖于对象的equals方法
 */

import com.lesama.domain.Student;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionTest1 {
    public static void main(String[] args) {
        Collection<Student> c = new ArrayList<Student>();
        c.add(new Student("张三", 18));
        c.add(new Student("李四", 19));
        c.add(new Student("王五", 20));
        System.out.println(c);
        System.out.println(c.contains(new Student("张三", 18)));
        System.out.println(c.remove(new Student("王五", 20)));
        System.out.println(c);
        collectionMethod2();
        System.out.println("-----------------------------");
        collectionMethod1();
    }

    private static void collectionMethod2() {
        Collection<String> stringCollection = new ArrayList<String>();
        stringCollection.add("爱有万分之一甜");
        stringCollection.add("宁愿我就葬在这一点");
        stringCollection.add("圈圈圆圆圈圈");
        stringCollection.add("甜甜黏黏甜甜的我~");
        System.out.println(stringCollection);
        System.out.println(stringCollection.remove("爱有万分之一天"));
        System.out.println(stringCollection.size());
        System.out.println(stringCollection.contains("爱有万分之一甜"));
        System.out.println(stringCollection.size());
        System.out.println(stringCollection);
        System.out.println(stringCollection.remove("爱有万分之一甜"));
        System.out.println(stringCollection);
        System.out.println(stringCollection.contains("爱有万分之一甜"));
        System.out.println(stringCollection.size());
    }

    private static void collectionMethod1() {
        Collection<String> stringCollection = new ArrayList<String>();
        stringCollection.add("风到这里就是黏");
        stringCollection.add("黏住过客的思念");
        stringCollection.add("雨到了这里缠成线");
        stringCollection.add("缠着我们留念人世间");
        System.out.println(stringCollection);
        // System.out.println(stringCollection.isEmpty());
        stringCollection.clear();
        System.out.println(stringCollection);
        // System.out.println(stringCollection.isEmpty());
    }
}
